//出差列表
function findBudgets(CertusFormAjax) {
    CertusFormAjax.ajax("findBudgets", {
        "flag": "NFYLC"
    }, function (response) {
        var data = response.data;
        var oabtColumns = [{
            id: 'budget_no',
            title: '费用编号',
            type: 'string',
            columnClass: 'text-center'
        }, {
            id: 'pro_name',
            title: '申请项目',
            type: 'string',
            columnClass: 'text-left',
        }, {
            id: 'buget',
            title: '申请总费用',
            type: 'string',
            width: 150,
            columnClass: 'text-center',
            resolution: function (value, record, column, grid, dataNo, columnNo) {
                var content = '￥' + value + '元';
                return content;
              }
        }, {
            id: 'apr_name',
            title: '申请人',
            type: 'string',
            width: 75,
            columnClass: 'text-center',
        }, {
            id: 'create_time',
            title: '申请时间',
            type: 'date',
            width: 100,
            format: 'yyyy-MM-dd',
            otype: 'time_stamp_ms',
            columnClass: 'text-center',
        }, {
            id: 'node_flag',
            title: '状态',
            type: 'string',
            width: 100,
            columnClass: 'text-center',
            resolution: function (value) {
                var content = '';
                if (value == "1") {
                    content = "申请待审批";
                } else if (value == "2") {
                    content = "申请被退回";
                } else if (value == "3") {
                    content = "申请不通过";
                } else if (value == "4") {
                    content = "申请不通过";
                } else {
                    content = "申请通过";
                }
                return content;
            }
        }, {
            id: 'operation',
            title: '操作',
            type: 'string',
            width: 75,
            columnClass: 'text-center',
            resolution: function (value, record) {
                var content = '';
                content += '<button class="btn btn-xs btn-primary" onclick="findDetail(\'' + record.process_instance_id + '\');">' +
                    '<i class="icon-eye-open"></i> 查看</button>';
                return content;
            }
        }];
        var oabtOption = {
            lang: 'zh-cn',
            ajaxLoad: false,
            // loadURL:'url',
            exportFileName: '费用申请列表',
            datas: data,
            columns: oabtColumns,
            gridContainer: 'oabtContainer',
            toolbarContainer: 'oabtToolBarContainer',
            tools: '',
            pageSize: 10,
            pageSizeLimit: [10, 15, 20]
        };
        oabtGrid = $.fn.dlshouwen.grid.init(oabtOption);
        oabtGrid.load();
    });

    this.findDetail = function (processId) {
        location.href = "#/budgetDetail/" + processId;
    }
}

function budgetDetail($scope, $routeParams, CertusFormAjax) {
    CertusFormAjax.ajax('findLcBugets', {
        "processId": $routeParams.processId
    }, function (response) {
        var data = response.data;
        $scope.proName = data[0].pro_name;
        $scope.proStage = data[0].buget_phase;
        $scope.userName = data[0].user_name;
        $scope.createTime = data[0].create_time;
        $scope.comments = data[0].comments;
        $scope.typeMoneys = data;
    });

    CertusFormAjax.ajax("findBudgetNodes", {
        "processId": $routeParams.processId
    }, function (result) {
        var data = result.data;
        var html = "";
        var dlength = data.length;
        for (var i = 0; i < dlength; i++) {
            html += "<li><span>" + data[i].createUser + "</span><span>" + data[i].createTime + "</span>";
            if (data[i].nodeFlag == 1) {
                html += "<span>发起申请</span>";
            } else if (data[i].nodeFlag == 2) {
                html += "<span>退回，审批意见：" + data[i].opinionMsg + "</span>";
            } else if (data[i].nodeFlag == 3) {
                html += "<span>拒绝，审批意见：" + data[i].opinionMsg + "</span>";
            } else if (data[i].nodeFlag == 4) {
                html += "<span>审批通过，审批意见：" + data[i].opinionMsg + "</span>";
            } else {
                html += "<span>审批通过，审批意见：" + data[i].opinionMsg + "</span>";
            }
            html += "</li>";
        };
        $("#containerUl").append(html);
    });
}

//出差列表
function findBudgets2(CertusFormAjax) {
    //查询审批人信息
    CertusFormAjax.ajax("findSpinfos",{"code":"%NFYLC%"},function(response){
        var data  = response.data;
        var oabtColumns = [{
            id: 'userName',
            title: '审批人',
            type: 'string',
            width: 75,
            columnClass: 'text-center',
        }
        // ,{
        //     id: 'departmentCode',
        //     title: '所属部门',
        //     type: 'string',
        //     columnClass: 'text-center',
        // }
        ,{
            id: 'company',
            title: '所属公司',
            type: 'string',
            columnClass: 'text-center',
            resolution: function (value, record) {
                var content = '';
                if (record.company=="HFKJ"){
                    content += '浩方科技';
                }else if (record.company=="HFXX"){
                    content += '浩方信息';
                }else if (record.company=="STSBJ"){
                    content += '赛特斯北京';
                }else if (record.company=="STSGD"){
                    content += '赛特斯广东';
                }else if (record.company=="STSJT"){
                    content += '赛特斯集团';
                }else if (record.company=="STSNJ"){
                    content += '赛特斯南京';
                }else if(record.company=="STSSH"){
                    content += '赛特斯上海';
                }else if(record.company=="SYB-RX"){
                    content += '融合运维事业部';
                }
                return content;
            }
        }, {
            id: 'comments',
            title: '职位',
            type: 'string',
            columnClass: 'text-center',
        }, {
            id: 'approveLevel',
            title: '审批级别',
            type: 'string',
            width: 75,
            columnClass: 'text-center',
        }, {
            id: 'minValue',
            title: '费用',
            type: 'string',
            width: 200,
            columnClass: 'text-center',
            resolution: function (value, record, column, grid, dataNo, columnNo) {
                var content = '￥' + value + '元';
                return content;
              }
        }];
        var oabtOption = {
            lang: 'zh-cn',
            ajaxLoad: false,
            // loadURL:'url',
            exportFileName: '审批人信息',
            datas:data,
            columns: oabtColumns,
            gridContainer: 'spContainer',
            toolbarContainer: 'spToolContainer',
            tools: '',
            pageSize: 10,
            pageSizeLimit: [10, 15, 20]
        };
        oabtGrid= $.fn.dlshouwen.grid.init(oabtOption);
        oabtGrid.load();
    });

    CertusFormAjax.ajax("findBudgets", {
        "flag": "NFYLC"
    }, function (response) {
        var data = response.data;
        var oabtColumns = [{
            id: 'pro_name',
            title: '申请项目',
            type: 'string',
            columnClass: 'text-left',
        }, {
            id: 'buget',
            title: '申请总费用',
            type: 'string',
            width: 150,
            columnClass: 'text-center',
            resolution: function (value, record, column, grid, dataNo, columnNo) {
                var content = '￥' + value + '元';
                return content;
              }
        }, {
            id: 'apr_name',
            title: '申请人',
            type: 'string',
            width: 75,
            columnClass: 'text-center',
        }, {
            id: 'create_time',
            title: '申请时间',
            type: 'date',
            width: 100,
            format: 'yyyy-MM-dd',
            otype: 'time_stamp_ms',
            columnClass: 'text-center',
        }, {
            id: 'node_flag',
            title: '状态',
            type: 'string',
            width: 100,
            columnClass: 'text-center',
            resolution: function (value) {
                var content = '';
                if (value == "1") {
                    content = "申请待审批";
                } else if (value == "2") {
                    content = "申请被退回";
                } else if (value == "3") {
                    content = "申请不通过";
                } else {
                    content = "申请通过";
                }
                return content;
            }
        }, {
            id: 'operation',
            title: '操作',
            type: 'string',
            width: 75,
            columnClass: 'text-center',
            resolution: function (value, record) {
                var content = '';
                content += '<button class="btn btn-xs btn-primary" onclick="findDetail(\'' + record.process_instance_id + '\');">' +
                    '<i class="icon-eye-open"></i> 查看</button>';
                return content;
            }
        }];
        var oabtOption = {
            lang: 'zh-cn',
            ajaxLoad: false,
            // loadURL:'url',
            exportFileName: '费用申请列表',
            datas: data,
            columns: oabtColumns,
            gridContainer: 'oabtContainer',
            toolbarContainer: 'oabtToolBarContainer',
            tools: '',
            pageSize: 10,
            pageSizeLimit: [10, 15, 20]
        };
        oabtGrid = $.fn.dlshouwen.grid.init(oabtOption);
        oabtGrid.load();
    });

    this.findDetail = function (processId) {
        location.href = "#/budgetDetail2/" + processId;
    }
}

function budgetDetail2($scope, $routeParams, CertusFormAjax) {
    CertusFormAjax.ajax('findYsBugets', {
        "processId": $routeParams.processId
    }, function (response) {
        var data = response.data;
        $scope.proName = data[0].pro_name;
        $scope.proStage = data[0].buget_phase;
        $scope.userName = data[0].user_name;
        $scope.createTime = data[0].create_time;
        $scope.comments = data[0].comments;
        $scope.typeMoneys = data;
    });

    CertusFormAjax.ajax("findBudgetNodes", {
        "processId": $routeParams.processId
    }, function (result) {
        var data = result.data;
        var html = "";
        var dlength = data.length;
        for (var i = 0; i < dlength; i++) {
            html += "<li><span>" + data[i].createUser + "</span><span>" + data[i].createTime + "</span>";
            if (data[i].nodeFlag == 1) {
                html += "<span>发起申请</span>";
            } else if (data[i].nodeFlag == 2) {
                html += "<span>退回，审批意见：" + data[i].opinionMsg + "</span>";
            } else if (data[i].nodeFlag == 3) {
                html += "<span>拒绝，审批意见：" + data[i].opinionMsg + "</span>";
            } else if (data[i].nodeFlag == 4) {
                html += "<span>审批通过，审批意见：" + data[i].opinionMsg + "</span>";
            } else {
                html += "<span>审批通过，审批意见：" + data[i].opinionMsg + "</span>";
            }
            html += "</li>";
        };
        $("#containerUl").append(html);
    });
}